package cn.edu.lsu.integratedsurvey.bean.vo;

import cn.edu.lsu.integratedsurvey.bean.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 登录返回VO对象
 *
 * @author Jasmine-drs
 * @date 2024/5/3 12:35
 */

@Data
public class LoginVo {
	@ApiModelProperty("id索引")
	private Integer id;
	@ApiModelProperty("姓名")
	private String name;
	@ApiModelProperty("账号")
	private String account;
	@ApiModelProperty("角色,0超级管理员，1普通管理员")
	private Integer role;
	@ApiModelProperty("部门")
	private String department;
	@ApiModelProperty("操作员id")
	private Integer operatorId;
	@ApiModelProperty("操作员姓名")
	private String operatorName;
	@ApiModelProperty("创建时间")
	private LocalDateTime createTime;
	@ApiModelProperty("更新时间")
	private LocalDateTime updateTime;
	@ApiModelProperty("jwt字符串")
	private String jwt;

	/**
	 * 将User对象转换为LoginVo对象,注意有些字段没有转换，需要手动转换操作员姓名、jwt
	 *
	 * @param user 用户完整对象
	 * @return 登录返回对象
	 */
	public static LoginVo convertToVo(User user) {
		LoginVo loginVo = new LoginVo();
		loginVo.setId(user.getId());
		loginVo.setName(user.getName());
		loginVo.setAccount(user.getAccount());
		loginVo.setRole(user.getRole());
		loginVo.setDepartment(user.getDepartment());
		loginVo.setOperatorId(user.getOperatorId());
		loginVo.setCreateTime(user.getCreateTime());
		loginVo.setUpdateTime(user.getUpdateTime());
		return loginVo;
	}
}
